﻿
$.parser.auto = false;
$(function () {
    $.messager.progress({
        text: '页面加载中....',
        interval: 100
    });
    $.parser.parse(window.document);
    window.setTimeout(function () {
        $.messager.progress('close');
        if (self != parent) {
            window.setTimeout(function () {
                parent.$.messager.progress('close');
            }, 500);
        }
    }, 1);
    $.parser.auto = true;

    $('input').each(function () {
        if ($(this).attr('required') || $(this).attr('validType'))
            $(this).validatebox();
    });
});
//关闭模式框
function closeDialog() {
    window.parent.$('#dd').dialog('close');
}
//弹出模式框
function openWindow(url, width, height) {
    if (width == undefined) width = 500;
    if (height == undefined) height = 300;
    if ($("#dd").length == 0) {
        var appendIframe = "<div>" +
        "<div id=\"dd\" icon=\"icon-save\" style=\"padding: 5px; width: 400px; height: 200px;\">" +
        "   <iframe scrolling=\"auto\" id='openXXXIframe' frameborder=\"0\" src=\"\" style=\"width: 100%;" +
        "      height: 100%;\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>" +
        "</div>" +
    "</div>";

        $("body").append(appendIframe);
    }
    $("#dd").dialog({
        title: "编辑",
        width: width,
        height: height,
        modal: true,
        onMove: function (left, top) {
            //            var right, bottom;
            //            //alert($("body").width()+"---"+left +"----"+ $("#divDialog").width()+"="+($("#divDialog").width()+left));  
            //            var bodyWidth = $("body").width();
            //            var bodyHeight = $("body").height();
            //            var dialogwidth = $("#dd").width();
            //            var dialogHeight = $("#dd").height();
            //            if (left < 0) {
            //                $("#dd").dialog("move", { left: 0, top: top });
            //            } else if ((left + dialogwidth) > (bodyWidth - 50)) {
            //                right = bodyWidth - dialogwidth - 50;
            //                $("#dd").dialog("move", { left: right, top: top });
            //            }
            //            if (top < 0) {
            //                $("#dd").dialog("move", { left: left, top: 0 });
            //            } else if (top > (bodyHeight - dialogHeight - 50)) {
            //                bottom = bodyHeight - dialogHeight - 50;
            //                $("#dd").dialog("move", { left: left, top: bottom });
            //            }
        }

    });
    $('#openXXXIframe')[0].src = url;
    //var wrapper = $("#dd").parent();
    //wrapper.animate({ top: 10 });
    //wrapper.next("div.window-shadow").animate({ top: 10 }, { duration: 0 });
}

//验证表单
function CheckV() {
    var flag = true;

    $('input').each(function () {
        if ($(this).attr('required') || $(this).attr('validType')) {

            if (!$(this).validatebox('isValid')) {
                flag = false;
                return;
            }
        }
    })
    return flag;
}
//confirm
function Confirm(msg, control) {
    $.messager.confirm("确认", msg, function (r) {
        if (r) {
            eval(control.toString().slice(11)); //截掉 javascript: 并执行
        }
    });
    return false;
}
//table头可选择列

function createColumnMenu(id) {
    var tmenu = $('<div id="tmenu" style="width:100px;"></div>').appendTo('body');
    var fields = $('#' + id).datagrid('getColumnFields');
    for (var i = 0; i < fields.length-1; i++) {
        $('<div iconCls="icon-ok"/>').html(fields[i]).appendTo(tmenu);
    }
    tmenu.menu({
        onClick: function (item) {
            if (item.iconCls == 'icon-ok') {
           
                $('#' + id).datagrid('hideColumn', item.text);
                tmenu.menu('setIcon', {
                    target: item.target,
                    iconCls: 'icon-empty'
                });
            } else {
                $('#' + id).datagrid('showColumn', item.text);
                tmenu.menu('setIcon', {
                    target: item.target,
                    iconCls: 'icon-ok'
                });
            }
        }
    });
}